from flask import Flask, request, jsonify
from flask import render_template
import datetime

from spider import csdn_parser

app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False

@app.route('/')
def hello_world():
    return 'Hello World!'


@app.route('/index')
def index():
    model = { 'nickname': 'Miguel' } # fake user
    return render_template("index.html",
        title = 'Home',
        model = model,
        datetime = datetime.date.today())


@app.route('/csdn/article/list')
def artiles():
    user = request.args.get('user')
    articles = csdn_parser.fetch_article_list(user)
    print(articles)
    rtn = dict()
    rtn['articles'] = articles
    return jsonify(rtn)


if __name__ == '__main__':
    app.run(port=8000)
